package com.shaoyu.spring.study.dto;

import lombok.Data;

/**
 * @Description:
 * @author: shaoyu1
 * @date: 2020/11/5 14:03:18
 */
@Data
public class BaseRequest<R> extends BasicData {

    private R request;

    public static <R> BaseRequest<R> build(R request){
        BaseRequest<R> baseRequest = new BaseRequest();
        baseRequest.request = request;
        return baseRequest;
    }
    @Override
    public <T> T get(String filedName){
        try{
            if(request==null)
                return super.get(filedName);
            T value = super.get(filedName,this.request);
            return value != null ? value : super.get(filedName);
        }catch (Exception e){
            return null;
        }
    }
    @Override
    public boolean set(String filedName, Object property){
        try {
            return request==null?super.set(filedName, property):super.set(filedName,request,property)||super.set(filedName, property);
        }catch (Exception e){
            return false;
        }
    }
}
